package com.ayou.eggguard.farm.controller;

import com.ayou.common.utils.PageBean;
import com.ayou.common.utils.Result;
import com.ayou.eggguard.farm.pojo.Caution;
import com.ayou.eggguard.farm.pojo.Treatment;
import com.ayou.eggguard.farm.service.TreatmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/treatment")
public class TreatmentController {

    @Autowired
    private TreatmentService treatmentService;

    @GetMapping("/getTreatmentList")
    public Result<PageBean<Treatment>> getTreatmentList(Integer pageNum,
                                                        Integer pageSize,
                                                        @RequestParam(required = false) String coopNumber){
        PageBean<Treatment> pb=treatmentService.getTreatmentList(pageNum,pageSize,coopNumber);
        return Result.success(pb);
    }

    @GetMapping("/delete")
    public Result delete(Integer id){
        treatmentService.delete(id);
        return Result.success();
    }

    @PostMapping("/add")
    public Result add(@RequestParam(required = false) Integer cautionId ,@RequestBody Treatment treatment){
        treatmentService.add(cautionId,treatment);
        return Result.success();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Treatment treatment){
        treatmentService.update(treatment);
        return Result.success();
    }
}
